---
title: "POQ Analysis Code"
author: "Hickel, Oskooii, Collingwood"
date: "June 16, 2023"
output:
  pdf_document:
    keep_tex: yes
    number_sections: yes
    toc: yes
  html_document:
    fig_caption: yes
    theme: cosmo
    toc: yes
theme: null
editor_options: 
  chunk_output_type: console
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = F, warning = F, message = F)
```


```{r Packages, include=FALSE}
library(tidyverse)
library(haven)
library(margins)
library(stargazer)
library(ggthemes)
library(broom)
library(magrittr)
library(ggridges)
library(survey)
library(descr)
library(reshape2) 
library(anesrake)
library(data.table) 
```


```{r Load Datasets, include=FALSE}

Lucid2020_short <- read_csv("Lucid2020_POQ.csv")

Lucid2022_short <- read_csv("Lucid2022_POQ.csv")

ANES2022 <- read_csv("ANES2022_POQ.csv")

CMPS2016 <- read_csv("CMPS2016_POQ.csv")

```



# Summary Stats 2020/21 Lucid 
```{r Summary Stats 2021 Lucid, results = "asis", eval = T}
stargazer(
  as.data.frame(Lucid2020_short), 
  summary.stat = c("mean", "median", "sd", "min", "max"),
   digits = 1,
  covariate.labels=c("Trump FT", "Romney FT", "Undocumented FT","Border Wall Support", "Deport Unath. 
                     Immigrants", "Immigrant Resentment", "Undocumented Distinction","Denial of Racism",  
                     "American$>$Latinx ID", "Right Wing Authoritarianism", 
                     "Socialism Anxiety", "Modern Sexism", "Linked Fate", 
                     "Economic Situation", "Discrimination", "Ideology (Lib-Con)", 
                     "Party ID (Dem-Rep)", 
                     "Political Knowledge", "Female", "Age", "Education", "Low Income", 
                     "Middle Income", 
                     "High Income", "Missing Income", "Native Born", "Spanish 
                     Language", "Protestant", 
                     "Religious Importance", "Mexican", "Cuban", "Puerto Rican", "Other Countries"),
  out = "Appendix_D1.tex",
  title="Lucid 2020-2021 Summary Statistics",
  label = "table_lucid_20-21_summary_stats")

```

# Summary Stats 2021/22 Lucid
```{r Summary Stats 2022 Lucid, results = "asis", eval = T}
stargazer(
   as.data.frame(Lucid2022_short), 
  summary.stat = c("mean", "median", "sd", "min", "max"),
   digits = 1,
  covariate.labels=c("Trump FT", "DeSantis FT ", "Undocumented FT","Border Wall Support", "Deport Unath. 
                     Immigrants", "Immigrant Resentment","Undocumented Distinction", "Denial of Racism",  
                     "American$>$Latinx ID", "Right Wing Authoritarianism", 
                     "Socialism Anxiety", "Modern Sexism", "Linked Fate", 
                     "Economic Situation", "Discrimination", 
                     "Immigrants Different Groups",
                     "Ideology (Lib-Con)", 
                     "Party ID (Dem-Rep)", "Female", "Age", "Education", "Low Income", 
                     "Middle Income", 
                     "High Income", "Missing Income", "Native Born", "Spanish 
                     Language", "Protestant", 
                     "Religious Importance", "Mexican", "Cuban", "Puerto Rican", "Other Countries"),
  out = "Appendix_D2.tex",
  title="Lucid 2021-2022 Summary Statistics",
  label = "table_lucid_22-22_summary_stats")




```


\newpage
#Create ACS 2016-2020 Target Weights
```{r, include=FALSE}
#Obtain ACS Estimates for Hispanic Population by Relevant Targets CODE (Saved Targed Provided in Replication Material/See next Chunk)

#Go to Census Website and download Latest ACS Estimates 
#https://www2.census.gov/programs-surveys/acs/data/pums/
#Select 2020 folder
#Then 5-Year
#Download “csv_pus.zip” ('us' is for the entire country)

#Obtain "Data Dictionary" To find the correct variables names: 
#https://www.census.gov/programs-surveys/acs/microdata/documentation.2020.html
#Direct link to dictionary: https://www2.census.gov/programs-surveys/acs/tech_docs/pums/data_dict/PUMS_Data_Dictionary_2016-2020.pdf


## Census data is too big, so selectively read in the variables you need.

a <- fread("csv_pus/psam_pusa.csv",
           select= c("HISP", "AGEP", "REGION",
                     "RAC1P", "SCHL", "SEX", "NATIVITY", "PWGTP"))

b <- fread("csv_pus/psam_pusb.csv",
           select= c("HISP", "AGEP", "REGION",
                     "RAC1P", "SCHL", "SEX", "NATIVITY", "PWGTP"))

c <- fread("csv_pus/psam_pusc.csv",
           select= c("HISP", "AGEP", "REGION",
                     "RAC1P", "SCHL", "SEX", "NATIVITY", "PWGTP"))

d <- fread("csv_pus/psam_pusd.csv",
           select= c("HISP", "AGEP", "REGION",
                     "RAC1P", "SCHL", "SEX", "NATIVITY", "PWGTP"))

# Combine the csvs
acs <- rbind(a,b,c,d)

# Clear the individual objects to save on memory
rm(a,b,c,d) 

# Restrict data to adults and Latinos (1=not Spanish, 2-23 diff. HISP subgroups)
acs_final<-acs %>% filter(AGEP>17 & HISP>1) 



####################################
#Create Target Variables and Recode # 
####################################

acs_final$FEMALE[acs_final$SEX==1] <- 1 #Male
acs_final$FEMALE[acs_final$SEX==2] <- 2 #Female


acs_final$region[acs_final$REGION==1] <- 1 # Northeast
acs_final$region[acs_final$REGION==2] <- 2 # Midwest
acs_final$region[acs_final$REGION==3] <- 3 # South
acs_final$region[acs_final$REGION==4] <- 4 # West


acs_final$agegroup[acs_final$AGEP<30] <- 1 # 18-29
acs_final$agegroup[acs_final$AGEP>=30 & acs_final$AGEP<40] <- 2 # 30-39
acs_final$agegroup[acs_final$AGEP>=40 & acs_final$AGEP<50] <-3 # 40-49
acs_final$agegroup[acs_final$AGEP>=50 & acs_final$AGEP<60] <- 4 # 50-59
acs_final$agegroup[acs_final$AGEP>=60] <- 5 # 60+


acs_final$EDUC[acs_final$SCHL<16] <- 1 # HS or less
acs_final$EDUC[acs_final$SCHL>=16 & acs_final$SCHL<18] <- 2 # HS or GED
acs_final$EDUC[acs_final$SCHL>=18 & acs_final$SCHL<21] <- 3 # Some college (up to AA)
acs_final$EDUC[acs_final$SCHL>=21] <- 4 # Bachelor degree or more


acs_final$native_born[acs_final$NATIVITY==2] <-1 #Foreign Born
acs_final$native_born[acs_final$NATIVITY==1] <-2 #Native Born



##################################
#Creating Population Benchmarks
##################################

# Create survey design object using ACS and weights
svy.acs <- svydesign(ids=~1, data=acs_final, weights=acs_final$PWGTP)

FEMALE <- svytable(~FEMALE, design=svy.acs) %>%
  prop.table() %>%
  round(digits=3) %>%
  as.numeric() #  Male 0.502  Female 0.498

region <- svytable(~region, design=svy.acs) %>%
  prop.table() %>%
  round(digits=3) %>%
  as.numeric() # NE 0.142 MW 0.086 S 0.379 W 0.393

agegroup <- svytable(~agegroup, design=svy.acs) %>%
  prop.table() %>%
  round(digits=3) %>%
  as.numeric() # 18-29: 0.284 30-39: 0.219 40-49: 0.192 50-59: 0.145  60+: 0.159

agegroup<-c(0.285, 0.219, 0.192, 0.145, 0.159)

EDUC <- svytable(~EDUC, design=svy.acs) %>%
  prop.table() %>%
  round(digits=3) %>%
  as.numeric() # Less HS:0.278 HS: 0.292 Some C: 0.275 College or more: 0.155


native_born <- svytable(~native_born, design=svy.acs) %>%
  prop.table() %>%
  round(digits=3) %>%
  as.numeric() # FB:0.455 Native: 0.545


#Finalize Targets
targets <- list(FEMALE, agegroup, EDUC, native_born)
names(targets) <- c("FEMALE", "agegroup", "EDUC",
                    "native_born")

saveRDS(targets, file="2016-2020 ACS Latino Weights.RDS")

```

##Load ACS Targets
```{r, include=FALSE}
targets<-readRDS("2016-2020 ACS Latino Weights.RDS")

```

##Weight Creation 2020 Lucid
```{r, include=FALSE}

#Create a unique case ID for Lucid Dataset
Lucid2020_short$ResponseId <- seq_along(Lucid2020_short[,1])


#Create a new dataset and Recode to match ANES response categories
lucid2020_short2<- Lucid2020_short %>% mutate(
                                              FEMALE= recode(FEMALE, 
                                                             "0"=1,
                                                             "1"=2), 
                                              agegroup= recode(agegroup,
                                                               "0"=1,
                                                               "1"=2, 
                                                               "2"=3,
                                                               "3"=4,
                                                               "4"=5), 
                                              EDUC= recode(EDUC, 
                                                           "0"=1,
                                                           "1"=2,
                                                           "2"=3,
                                                           "3"=4), 
                                              native_born= recode(native_born, 
                                                                  "0"=1, 
                                                                  "1"=2)
                                                )


lucid2020_short2<- as.data.frame(lucid2020_short2)

# Create the weights
myweights <- anesrake(targets, lucid2020_short2,
                      caseid = lucid2020_short2$ResponseId, cap = 5, type = "nolim")


# Store the weights as a variable in our Lucid2020_short dataset 
Lucid2020_short$weight <- unlist(myweights[1])

#Check Weight Distribution
hist(Lucid2020_short$weight); mean(Lucid2020_short$weight)

#Weight Summary
summary(Lucid2020_short$weight)


#Compare unweighted to weighted proportions

targets 

CrossTable(Lucid2020_short$FEMALE)
crosstab(Lucid2020_short$FEMALE, rep(1, nrow(Lucid2020_short)), weight = Lucid2020_short$weight, plot=F, prop.r=T)

CrossTable(Lucid2020_short$agegroup)
crosstab(Lucid2020_short$agegroup, rep(1, nrow(Lucid2020_short)), weight = Lucid2020_short$weight, plot=F, prop.r=T)

CrossTable(Lucid2020_short$EDUC)
crosstab(Lucid2020_short$EDUC, rep(1, nrow(Lucid2020_short)), weight = Lucid2020_short$weight, plot=F, prop.r=T)

CrossTable(Lucid2020_short$native_born)
crosstab(Lucid2020_short$native_born, rep(1, nrow(Lucid2020_short)), weight = Lucid2020_short$weight, plot=F, prop.r=T)


```


##Weight Creation 2022 Lucid
```{r, include=FALSE}

##########################################
#Create a unique case ID for Lucid Dataset
Lucid2022_short$ResponseId <- seq_along(Lucid2022_short[,1])


#Create a new dataset and Recode to match ANES response categories
Lucid2022_short2<- Lucid2022_short %>% mutate(
                                              FEMALE= recode(FEMALE, 
                                                             "0"=1,
                                                             "1"=2), 
                                              agegroup= recode(agegroup,
                                                               "0"=1,
                                                               "1"=2, 
                                                               "2"=3,
                                                               "3"=4,
                                                               "4"=5), 
                                              EDUC= recode(EDUC, 
                                                           "0"=1,
                                                           "1"=2,
                                                           "2"=3,
                                                           "3"=4), 
                                              native_born= recode(native_born, 
                                                                  "0"=1, 
                                                                  "1"=2)
                                                )


Lucid2022_short2<-as.data.frame(Lucid2022_short2)

# Create the weights
myweights_22 <- anesrake(targets, Lucid2022_short2,
                      caseid = Lucid2022_short2$ResponseId, cap = 5, type = "nolim")


# Store the weights as a variable in our Lucid2020_short dataset 
Lucid2022_short$weight <- unlist(myweights_22[1])

#Check Weight Distribution
hist(Lucid2022_short$weight); mean(Lucid2022_short$weight)

#Weight Summary
summary(Lucid2022_short$weight)



#Compare unweighted to weighted proportions

targets 

CrossTable(Lucid2022_short$FEMALE)
crosstab(Lucid2022_short$FEMALE, rep(1, nrow(Lucid2022_short)), weight = Lucid2022_short$weight, plot=F, prop.r=T)

CrossTable(Lucid2022_short$agegroup)
crosstab(Lucid2022_short$agegroup, rep(1, nrow(Lucid2022_short)), weight = Lucid2022_short$weight, plot=F, prop.r=T)

CrossTable(Lucid2022_short$EDUC)
crosstab(Lucid2022_short$EDUC, rep(1, nrow(Lucid2022_short)), weight = Lucid2022_short$weight, plot=F, prop.r=T)

CrossTable(Lucid2022_short$native_born)
crosstab(Lucid2022_short$native_born, rep(1, nrow(Lucid2022_short)), weight = Lucid2022_short$weight, plot=F, prop.r=T)

```



# Bar Plot 2020 Lucid
```{r bar plot 2020, include=FALSE}


iv_dat <- Lucid2020_short %>% dplyr::select(RESENTNEGSCALE, weight) %>%
                              data.frame()
 
iv_dat2 <- Lucid2020_short %>% filter(USLATINXID<0) %>% dplyr::select(RESENTNEGSCALE, weight) %>% data.frame()
 
iv_dat3 <- Lucid2020_short %>% filter(USLATINXID>0) %>% dplyr::select(RESENTNEGSCALE, weight) %>% data.frame()
 
ggplot(data=iv_dat, aes(x=RESENTNEGSCALE, weight=weight))  +
  geom_histogram(aes(y =..density..), binwidth = 1, color = "gray8", fill = "#FF6666") +
  scale_y_continuous("Percent", labels = scales::percent, breaks =  seq(0, .35, .05), limits=c(0,.37)) +
  scale_x_continuous("Immigrant Resentment (Low to High)") +
  theme_light()+
  theme(legend.position = "none",
        plot.title = element_text(size=24, hjust = .5, face="bold", family = "serif"),
        plot.subtitle = element_text(size=20, hjust = .5, face="italic", family = "serif"),
        axis.title.x = element_text(size=25, hjust = .5, family = "serif"), #% Immigrant Resentment
        axis.title.y = element_text(size=25, hjust = .5, family = "serif"), #% percent
        #plot.caption = element_text(size=10, hjust = .5, face="bold", family = "serif"),
        axis.text.y = element_text(size = 16, family = "serif"),
        axis.text.x = element_text(size = 16, family = "serif"),
        legend.title =element_text(size=12, face="bold", family = "serif"),
        legend.text =element_text(size=12, face="bold", family = "serif"),
        strip.text.x = element_text(size=15, face="bold",family = "serif")
        )#panel text size
  ggsave("Figure5.png",
         width = 10, height = 7)
 
  
ggplot(data=iv_dat2, aes(x=RESENTNEGSCALE, weight=weight))  +
  geom_histogram(aes(y =..density..), binwidth = 1, color = "gray8", fill = "#FF6666") +
  scale_y_continuous("Percent", labels = scales::percent, breaks =  seq(0, .35, .05), limits=c(0,.37)) +
  scale_x_continuous("Immigrant Resentment (Low to High)") +
  theme_light()+
  theme(legend.position = "none",
        plot.title = element_text(size=24, hjust = .5, face="bold", family = "serif"),
        plot.subtitle = element_text(size=20, hjust = .5, face="italic", family = "serif"),
        axis.title.x = element_text(size=25, hjust = .5, family = "serif"), #% Immigrant Resentment
        axis.title.y = element_text(size=25, hjust = .5, family = "serif"), #% percent
        #plot.caption = element_text(size=10, hjust = .5, face="bold", family = "serif"),
        axis.text.y = element_text(size = 16, family = "serif"),
        axis.text.x = element_text(size = 16, family = "serif"),
        legend.title =element_text(size=12, face="bold", family = "serif"),
        legend.text =element_text(size=12, face="bold", family = "serif"),
        strip.text.x = element_text(size=15, face="bold",family = "serif")
        )#panel text size
    ggsave("FigureE2.png",
         width = 10, height = 7)
   
ggplot(data=iv_dat3, aes(x=RESENTNEGSCALE, weight=weight))  +
  geom_histogram(aes(y =..density..), binwidth = 1, color = "gray8", fill = "#FF6666") +
  scale_y_continuous("Percent", labels = scales::percent, breaks =  seq(0, .35, .05), limits=c(0,.37)) +
  scale_x_continuous("Immigrant Resentment (Low to High)") +
 theme_light()+
  theme(legend.position = "none",
        plot.title = element_text(size=24, hjust = .5, face="bold", family = "serif"),
        plot.subtitle = element_text(size=20, hjust = .5, face="italic", family = "serif"),
        axis.title.x = element_text(size=25, hjust = .5, family = "serif"), #% Immigrant Resentment
        axis.title.y = element_text(size=25, hjust = .5, family = "serif"), #% percent
        #plot.caption = element_text(size=10, hjust = .5, face="bold", family = "serif"),
        axis.text.y = element_text(size = 16, family = "serif"),
        axis.text.x = element_text(size = 16, family = "serif"),
        legend.title =element_text(size=12, face="bold", family = "serif"),
        legend.text =element_text(size=12, face="bold", family = "serif"),
        strip.text.x = element_text(size=15, face="bold",family = "serif")
        )#panel text size
    ggsave("FigureE1.png",
         width = 10, height = 7)
   


```


# Bar Plot 2022 Lucid
```{r bar plot 2022, include=FALSE}

iv_dat_22 <- Lucid2022_short %>% dplyr::select(RESENTNEGSCALE, weight) %>%
                              data.frame()
 
iv_dat_22_2 <- Lucid2022_short %>% filter(USLATINXID<0) %>% dplyr::select(RESENTNEGSCALE, weight) %>% data.frame()
 
iv_dat_22_3 <- Lucid2022_short %>% filter(USLATINXID>0) %>% dplyr::select(RESENTNEGSCALE, weight) %>% data.frame()
 
 
ggplot(data=iv_dat_22, aes(x=RESENTNEGSCALE, weight=weight))  +
   geom_histogram(aes(y =..density..), binwidth = 1, color = "gray8", fill = "#FF6666") +
  scale_y_continuous("Percent", labels = scales::percent, breaks =  seq(0, .35, .05), limits=c(0,.37)) +
  scale_x_continuous("Immigrant Resentment (Low to High)") +
  theme_light()+
  theme(legend.position = "none",
        plot.title = element_text(size=24, hjust = .5, face="bold", family = "serif"),
        plot.subtitle = element_text(size=20, hjust = .5, face="italic", family = "serif"),
        axis.title.x = element_text(size=25, hjust = .5, family = "serif"), #% Immigrant Resentment
        axis.title.y = element_text(size=25, hjust = .5, family = "serif"), #% percent
        #plot.caption = element_text(size=10, hjust = .5, face="bold", family = "serif"),
        axis.text.y = element_text(size = 16, family = "serif"),
        axis.text.x = element_text(size = 16, family = "serif"),
        legend.title =element_text(size=12, face="bold", family = "serif"),
        legend.text =element_text(size=12, face="bold", family = "serif"),
        strip.text.x = element_text(size=15, face="bold",family = "serif")
        )#panel text size
  ggsave("Figure6.png",
         width = 10, height = 7)
 
ggplot(data=iv_dat_22_2, aes(x=RESENTNEGSCALE, weight=weight))  +
   geom_histogram(aes(y =..density..), binwidth = 1, color = "gray8", fill = "#FF6666") +
  scale_y_continuous("Percent", labels = scales::percent, breaks =  seq(0, .35, .05), limits=c(0,.37)) +
  scale_x_continuous("Immigrant Resentment (Low to High)") +
  theme_light()+
  theme(legend.position = "none",
        plot.title = element_text(size=24, hjust = .5, face="bold", family = "serif"),
        plot.subtitle = element_text(size=20, hjust = .5, face="italic", family = "serif"),
        axis.title.x = element_text(size=25, hjust = .5, family = "serif"), #% Immigrant Resentment
        axis.title.y = element_text(size=25, hjust = .5, family = "serif"), #% percent
        #plot.caption = element_text(size=10, hjust = .5, face="bold", family = "serif"),
        axis.text.y = element_text(size = 16, family = "serif"),
        axis.text.x = element_text(size = 16, family = "serif"),
        legend.title =element_text(size=12, face="bold", family = "serif"),
        legend.text =element_text(size=12, face="bold", family = "serif"),
        strip.text.x = element_text(size=15, face="bold",family = "serif")
        )#panel text size
  ggsave("FigureE4.png",
         width = 10, height = 7)
 
ggplot(data=iv_dat_22_3, aes(x=RESENTNEGSCALE, weight=weight))  +
   geom_histogram(aes(y =..density..), binwidth = 1, color = "gray8", fill = "#FF6666") +
  scale_y_continuous("Percent", labels = scales::percent, breaks =  seq(0, .35, .05), limits=c(0,.37)) +
  scale_x_continuous("Immigrant Resentment (Low to High)") +
  theme_light()+
  theme(legend.position = "none",
        plot.title = element_text(size=24, hjust = .5, face="bold", family = "serif"),
        plot.subtitle = element_text(size=20, hjust = .5, face="italic", family = "serif"),
        axis.title.x = element_text(size=25, hjust = .5, family = "serif"), #% Immigrant Resentment
        axis.title.y = element_text(size=25, hjust = .5, family = "serif"), #% percent
        #plot.caption = element_text(size=10, hjust = .5, face="bold", family = "serif"),
        axis.text.y = element_text(size = 16, family = "serif"),
        axis.text.x = element_text(size = 16, family = "serif"),
        legend.title =element_text(size=12, face="bold", family = "serif"),
        legend.text =element_text(size=12, face="bold", family = "serif"),
        strip.text.x = element_text(size=15, face="bold",family = "serif")
        )#panel text size
  ggsave("FigureE3.png",
         width = 10, height = 7)
```



#Regression Models \& PR Values 
```{r 2020 Trump Models and Margins, include=FALSE}

# Trump Therm #
summary(trump_short_2020<- lm (FTTRUMP ~ RESENTNEGSCALE,
              data = Lucid2020_short, weights = weight))



summary(trump_main_2020 <- lm (FTTRUMP ~ RESENTNEGSCALE + DENYSCALE + USLATINXID + RWASCALE + SOCGEN + 
                    MODSEXISM + LF + ECON+ PDISCRIM+ 
                    IDEOLOGY + PARTYID+ PKSCALE + 
                    FEMALE + agegroup + EDUC + LT40 + INCOME4080 + INCOMEMISSING +
                    native_born + SPANLANG + PROT + RELIGIOSITY +
                    CUBA + PR+ OTHER_CO,
             data = Lucid2020_short, weights = weight))


margin_trump_2020 <- as.data.frame(summary(margins(trump_main_2020,variables=c("RESENTNEGSCALE",  "DENYSCALE", "USLATINXID", "RWASCALE", "SOCGEN", "MODSEXISM", "LF", "ECON","PDISCRIM", "IDEOLOGY", "PARTYID"), change = "minmax"))) %>% select(c("AME","lower","upper", "factor"))

```


```{r 2022 Trump Models and Margins, include=FALSE}

# Trump Therm #
summary(trump_short_2022<- lm (FTTRUMP ~ RESENTNEGSCALE,
                               data = Lucid2022_short, weights = weight))


summary(trump_main_2022 <- lm (FTTRUMP ~ RESENTNEGSCALE + DENYSCALE + USLATINXID + RWASCALE + SOCGEN + 
                                 MODSEXISM + LF + ECON+ PDISCRIM+ 
                                 IDEOLOGY + PARTYID + 
                                 FEMALE + agegroup + EDUC + LT40 + INCOME4080 + INCOMEMISSING +
                                 native_born + SPANLANG + PROT + RELIGIOSITY +
                                 CUBA + PR + OTHER_CO,
                               data = Lucid2022_short, weights = weight))


margin_trump_2022 <- as.data.frame(summary(margins(trump_main_2022,variables=c("RESENTNEGSCALE",  "DENYSCALE", "USLATINXID", "RWASCALE", "SOCGEN", "MODSEXISM", "LF", "ECON","PDISCRIM", "IDEOLOGY", "PARTYID"), change = "minmax"))) %>% select(c("AME","lower","upper", "factor"))

```


```{r 2020 Romney Models and Margins, include=FALSE}

# Romney Therm #
summary(romney_short_2020<- lm (FTROMNEY ~ RESENTNEGSCALE,
              data = Lucid2020_short, weights = weight))


summary(romney_main_2020 <- lm (FTROMNEY ~ RESENTNEGSCALE + DENYSCALE + USLATINXID + RWASCALE + SOCGEN + 
                    MODSEXISM + LF + ECON+ PDISCRIM+ 
                    IDEOLOGY + PARTYID+ PKSCALE + 
                    FEMALE + agegroup + EDUC + LT40 + INCOME4080 + INCOMEMISSING +
                    native_born + SPANLANG + PROT + RELIGIOSITY +
                      CUBA + PR + OTHER_CO,
             data = Lucid2020_short, weights = weight))

#Margins
margin_romney_2020 <- as.data.frame(summary(margins(romney_main_2020,variables=c("RESENTNEGSCALE",  "DENYSCALE", "USLATINXID", "RWASCALE", "SOCGEN", "MODSEXISM", "LF", "ECON","PDISCRIM", "IDEOLOGY", "PARTYID"), change = "minmax"))) %>% select(c("AME","lower","upper", "factor"))

```


```{r 2022 DeSantis Models and Margins, include=FALSE}

# DeSantis Therm #
summary(desantis_short_2022<- lm (FTDESANTIS ~ RESENTNEGSCALE,
                                data = Lucid2022_short, weights = weight))


summary(desantis_main_2022 <- lm (FTDESANTIS ~ RESENTNEGSCALE + DENYSCALE + USLATINXID + RWASCALE + SOCGEN + 
                                  MODSEXISM + LF + ECON+ PDISCRIM+ 
                                  IDEOLOGY + PARTYID + 
                                  FEMALE + agegroup + EDUC + LT40 + INCOME4080 + INCOMEMISSING +
                                  native_born + SPANLANG + PROT + RELIGIOSITY +
                                  CUBA + PR+ OTHER_CO,
                                data = Lucid2022_short, weights = weight))

#Margins
margin_desantis_2022 <- as.data.frame(summary(margins(desantis_main_2022,variables=c("RESENTNEGSCALE",  "DENYSCALE", "USLATINXID", "RWASCALE", "SOCGEN", "MODSEXISM", "LF", "ECON","PDISCRIM", "IDEOLOGY", "PARTYID"), change = "minmax"))) %>% select(c("AME","lower","upper", "factor"))

```




```{r 2020 Wall Models and Margins, include=FALSE}
# Build a Wall # (0-4)
summary(wall_short_2020<- lm (WALL ~ RESENTNEGSCALE,
              data = Lucid2020_short, weights = weight))


summary(wall_main_2020 <- lm (WALL ~ RESENTNEGSCALE + DENYSCALE + USLATINXID + RWASCALE + SOCGEN + 
                    MODSEXISM + LF + ECON+ PDISCRIM+ 
                    IDEOLOGY + PARTYID+ PKSCALE + 
                    FEMALE + agegroup + EDUC + LT40 + INCOME4080 + INCOMEMISSING +
                    native_born + SPANLANG + PROT + RELIGIOSITY +
                     CUBA + PR+ OTHER_CO,
             data = Lucid2020_short, weights = weight))


#Margins
margin_wall_2020 <- as.data.frame(summary(margins(wall_main_2020,variables=c("RESENTNEGSCALE",  "DENYSCALE", "USLATINXID", "RWASCALE", "SOCGEN", "MODSEXISM", "LF", "ECON","PDISCRIM", "IDEOLOGY", "PARTYID"), change = "minmax"))) %>% select(c("AME","lower","upper", "factor"))

```


```{r 2022 Wall Models and Margins, include=FALSE}
# Build a Wall # (0-4)
summary(wall_short_2022<- lm (WALL ~ RESENTNEGSCALE,
                              data = Lucid2022_short, weights = weight))


summary(wall_main_2022 <- lm (WALL ~ RESENTNEGSCALE + DENYSCALE + USLATINXID + RWASCALE + SOCGEN + 
                                MODSEXISM + LF + ECON+ PDISCRIM+ 
                                IDEOLOGY + PARTYID + 
                                FEMALE + agegroup + EDUC + LT40 + INCOME4080 + INCOMEMISSING +
                                native_born + SPANLANG + PROT + RELIGIOSITY +
                                 CUBA + PR+ OTHER_CO,
                              data = Lucid2022_short, weights = weight))


#Margins
margin_wall_2022 <- as.data.frame(summary(margins(wall_main_2022,variables=c("RESENTNEGSCALE",  "DENYSCALE", "USLATINXID", "RWASCALE", "SOCGEN", "MODSEXISM", "LF", "ECON","PDISCRIM", "IDEOLOGY", "PARTYID"), change = "minmax"))) %>% select(c("AME","lower","upper", "factor"))

```


```{r 2020 Undoc Imm. Policy Models and Margins, include=FALSE}

# "Illegal" Immigration Policy--Deport Unauthorized Immigrants #
summary(img_short_2020<- lm (IMG ~ RESENTNEGSCALE,
              data = Lucid2020_short, weights = weight))


summary(img_main_2020 <- lm (IMG ~ RESENTNEGSCALE + DENYSCALE + USLATINXID + RWASCALE + SOCGEN + 
                    MODSEXISM + LF + ECON+ PDISCRIM+ 
                    IDEOLOGY + PARTYID+ PKSCALE + 
                    FEMALE + agegroup + EDUC + LT40 + INCOME4080 + INCOMEMISSING +
                    native_born + SPANLANG + PROT + RELIGIOSITY +
                     CUBA + PR+ OTHER_CO,
             data = Lucid2020_short, weights = weight))

#Margins
margin_img_2020<- as.data.frame(summary(margins(img_main_2020,variables=c("RESENTNEGSCALE",  "DENYSCALE", "USLATINXID", "RWASCALE", "SOCGEN", "MODSEXISM", "LF", "ECON","PDISCRIM", "IDEOLOGY", "PARTYID"), change = "minmax"))) %>% select(c("AME","lower","upper", "factor"))

```


```{r 2022 Undoc Imm. Policy Models and Margins, include=FALSE}

# "Illegal" Immigration Policy--Deport Unauthorized Immigrants #
summary(img_short_2022<- lm (IMG ~ RESENTNEGSCALE,
                             data = Lucid2022_short, weights = weight))


summary(img_main_2022 <- lm (IMG ~ RESENTNEGSCALE + DENYSCALE + USLATINXID + RWASCALE + SOCGEN + 
                               MODSEXISM + LF + ECON+ PDISCRIM+ 
                               IDEOLOGY + PARTYID + 
                               FEMALE + agegroup + EDUC + LT40 + INCOME4080 + INCOMEMISSING +
                               native_born + SPANLANG + PROT + RELIGIOSITY +
                              CUBA + PR+ OTHER_CO,
                             data = Lucid2022_short, weights = weight))

#Margins
margin_img_2022<- as.data.frame(summary(margins(img_main_2022,variables=c("RESENTNEGSCALE",  "DENYSCALE", "USLATINXID", "RWASCALE", "SOCGEN", "MODSEXISM", "LF", "ECON","PDISCRIM", "IDEOLOGY", "PARTYID"), change = "minmax"))) %>% select(c("AME","lower","upper", "factor"))

```



```{r 2020 Undoc Imm. FT Models and Margins, include=FALSE}

# "Illegal" Immigration FT #
summary(img_FT_short_2020<- lm ( FTUNDOCUMENTED~ RESENTNEGSCALE,
              data = Lucid2020_short, weights = weight))


summary(img_FT_main_2020 <- lm (FTUNDOCUMENTED ~ RESENTNEGSCALE + DENYSCALE + USLATINXID + RWASCALE + SOCGEN + 
                    MODSEXISM + LF + ECON+ PDISCRIM+ 
                    IDEOLOGY + PARTYID+ PKSCALE + 
                    FEMALE + agegroup + EDUC + LT40 + INCOME4080 + INCOMEMISSING +
                    native_born + SPANLANG + PROT + RELIGIOSITY +
                     CUBA + PR+ OTHER_CO,
             data = Lucid2020_short, weights = weight))


#Margins
margin_img_FT_2020<- as.data.frame(summary(margins(img_FT_main_2020, variables=c("RESENTNEGSCALE",  "DENYSCALE", "USLATINXID", "RWASCALE", "SOCGEN", "MODSEXISM", "LF", "ECON","PDISCRIM", "IDEOLOGY", "PARTYID"), change = "minmax"))) %>% select(c("AME","lower","upper", "factor"))

```



```{r 2022 Undoc Imm. FT Models and Margins, include=FALSE}

# "Illegal" Immigration FT #
summary(img_FT_short_2022<- lm ( FTUNDOCUMENTED~ RESENTNEGSCALE,
                                 data = Lucid2022_short, weights = weight))


summary(img_FT_main_2022 <- lm (FTUNDOCUMENTED ~ RESENTNEGSCALE + DENYSCALE + USLATINXID + RWASCALE + SOCGEN + 
                                  MODSEXISM + LF + ECON+ PDISCRIM+ 
                                  IDEOLOGY + PARTYID + 
                                  FEMALE + agegroup + EDUC + LT40 + INCOME4080 + INCOMEMISSING +
                                  native_born + SPANLANG + PROT + RELIGIOSITY +
                                   CUBA + PR+ OTHER_CO,
                                data = Lucid2022_short, weights = weight))


#Margins
margin_img_FT_2022<- as.data.frame(summary(margins(img_FT_main_2022, variables=c("RESENTNEGSCALE",  "DENYSCALE", "USLATINXID", "RWASCALE", "SOCGEN", "MODSEXISM", "LF", "ECON","PDISCRIM", "IDEOLOGY", "PARTYID"), change = "minmax"))) %>% select(c("AME","lower","upper", "factor"))

```



```{r 2020 Undoc Imm. Distinction Models and Margins, include=FALSE}

# "Illegal" Immigration Distinction #
summary(img_disct_short_2020<- lm (RESENT8~ RESENTNEGSCALE,
              data = Lucid2020_short, weights = weight))


summary(img_disct_main_2020 <- lm (RESENT8 ~ RESENTNEGSCALE + DENYSCALE + USLATINXID + RWASCALE + SOCGEN + 
                    MODSEXISM + LF + ECON+ PDISCRIM+ 
                    IDEOLOGY + PARTYID+ PKSCALE + 
                    FEMALE + agegroup + EDUC + LT40 + INCOME4080 + INCOMEMISSING +
                    native_born + SPANLANG + PROT + RELIGIOSITY +
                     CUBA + PR+ OTHER_CO,
             data = Lucid2020_short, weights = weight))



#Margins
margin_img_disct_2020<- as.data.frame(summary(margins(img_disct_main_2020, variables=c("RESENTNEGSCALE",  "DENYSCALE", "USLATINXID", "RWASCALE", "SOCGEN", "MODSEXISM", "LF", "ECON","PDISCRIM", "IDEOLOGY", "PARTYID"), change = "minmax"))) %>% select(c("AME","lower","upper", "factor"))

```



```{r 2022 Undoc Imm. Distinction Models and Margins, include=FALSE}

# "Illegal" Immigration Distinction #
summary(img_disct_short_2022<- lm(insult2~ RESENTNEGSCALE,
                                    data = Lucid2022_short, weights = weight))


summary(img_disct_main_2022 <- lm(insult2 ~ RESENTNEGSCALE + DENYSCALE + USLATINXID + RWASCALE + SOCGEN + 
                                     MODSEXISM + LF + ECON+ PDISCRIM+ 
                                     IDEOLOGY + PARTYID + 
                                     FEMALE + agegroup + EDUC + LT40 + INCOME4080 + INCOMEMISSING +
                                     native_born + SPANLANG + PROT + RELIGIOSITY +
                                     CUBA + PR+ OTHER_CO,
                                   data = Lucid2022_short, weights = weight))



#Margins
margin_img_disct_2022<- as.data.frame(summary(margins(img_disct_main_2022, variables=c("RESENTNEGSCALE",  "DENYSCALE", "USLATINXID", "RWASCALE", "SOCGEN", "MODSEXISM", "LF", "ECON","PDISCRIM", "IDEOLOGY", "PARTYID"), change = "minmax"))) %>% select(c("AME","lower","upper", "factor"))

```


```{r 2020 Predict Resent Models and Margins, include=FALSE}

# Who is resentful of immigrants? #
summary(resent_predict_2020<- lm (RESENTNEGSCALE~ PDISCRIM + IDEOLOGY + PARTYID+ PKSCALE + 
                    FEMALE + agegroup + EDUC + LT40 + INCOME4080 + INCOMEMISSING +
                    native_born + SPANLANG + PROT + RELIGIOSITY +
                  CUBA + PR+ OTHER_CO,
              data = Lucid2020_short, weights = weight))

```


```{r 2022 Predict Resent Models and Margins, include=FALSE}

# Who is resentful of immigrants? #
summary(resent_predict_2022<- lm (RESENTNEGSCALE~ PDISCRIM + IDEOLOGY + PARTYID + 
                                    FEMALE + agegroup + EDUC + LT40 + INCOME4080 + INCOMEMISSING +
                                    native_born + SPANLANG + PROT + RELIGIOSITY +
                                   CUBA + PR+ OTHER_CO,
                                  data = Lucid2022_short, weights = weight))

```



```{r 2022 Imms. Are Diff. Groups Models and Margins, include=FALSE}

# "Illegal" Immigration Distinction #
summary(img_diffgroup_short_2022<- lm(diffgroup~ RESENTNEGSCALE,
                                  data = Lucid2022_short, weights = weight))


summary(img_diffgroup_main_2022 <- lm(diffgroup ~ RESENTNEGSCALE + DENYSCALE + USLATINXID + RWASCALE + SOCGEN + 
                                    MODSEXISM + LF + ECON+ PDISCRIM+ 
                                    IDEOLOGY + PARTYID + 
                                    FEMALE + agegroup + EDUC + LT40 + INCOME4080 + INCOMEMISSING +
                                    native_born + SPANLANG + PROT + RELIGIOSITY +
                                     CUBA + PR+ OTHER_CO,
                                  data = Lucid2022_short, weights = weight))



#Margins
margin_img_diffgroup_2022<- as.data.frame(summary(margins(img_diffgroup_main_2022, variables=c("RESENTNEGSCALE",  "DENYSCALE", "USLATINXID", "RWASCALE", "SOCGEN", "MODSEXISM", "LF", "ECON","PDISCRIM", "IDEOLOGY", "PARTYID"), change = "minmax"))) %>% select(c("AME","lower","upper", "factor"))

```



\newpage
## Trump and Romney Therm Table 2020 Lucid
```{r, results = "asis", eval = T}
tab_labels <- c( "Immigrant Resentment", "Denial of Racism", "American$>$Latinx ID", 
                     "Right Wing Authoritarianism", "Socialism Anxiety", "Modern Sexism", "Linked Fate", 
                     "Economic Situation", "Discrimination", "Ideology (Lib-Con)", "Party ID (Dem-Rep)",
                     "Political Knowledge", "Female", "Age", "Education", "Low Income", 
                     "Middle Income", "Missing Income", "Native Born", "Spanish Language", 
                     "Protestant","Religious Importance", "Cuban", "Puerto Rican", "Other Countries")

stargazer(trump_short_2020, trump_main_2020, romney_short_2020, romney_main_2020, style="ajps", out.header=F,
         model.numbers = TRUE,
         covariate.labels = tab_labels,
         dep.var.labels =  c("Trump FT",  "Romney FT"),
         out = "Appendix_E7.tex", 
         label = "table_trump_romney_ft_lucid2020",
         font.size = "scriptsize",
         star.char = c("\\#", "**", "***"), 
          star.cutoffs = c(.1, .05, .01),
          notes = "$^{***}$p $<$ .01; $^{**}$p $<$ .05; $^{\\#}$p $<$ .1",
          notes.append = F,
         column.sep.width = "2pt",
         omit.stat = c("ser","f"),
         title = "Predictors of feelings towards Donald Trump and Mitt Romney (0-100), 2020/21 Lucid"
         )
```


\newpage
## Trump Therm Table 2022 Lucid
```{r, results = "asis", eval = T}
tab_labels <- c( "Immigrant Resentment", "Denial of Racism", "American$>$Latinx ID", 
                     "Right Wing Authoritarianism", "Socialism Anxiety", "Modern Sexism", "Linked Fate", 
                     "Economic Situation", "Discrimination", "Ideology (Lib-Con)", "Party ID (Dem-Rep)",
                      "Female", "Age", "Education", "Low Income", 
                     "Middle Income", "Missing Income", "Native Born", "Spanish Language", 
                     "Protestant","Religious Importance", "Cuban", "Puerto Rican", "Other Countries")


stargazer(trump_short_2022, trump_main_2022, desantis_short_2022, desantis_main_2022, 
          style="ajps", 
          out.header=F,
         model.numbers = TRUE,
         covariate.labels = tab_labels,
         dep.var.labels =  c("Trump FT",  "DeSantis FT"),
         out = "Appendix_E8.tex", 
         label = "table_trump_ft_DeSantis_lucid2022",
         font.size = "scriptsize",
         star.char = c("\\#", "**", "***"), 
          star.cutoffs = c(.1, .05, .01),
          notes = "$^{***}$p $<$ .01; $^{**}$p $<$ .05; $^{\\#}$p $<$ .1",
          notes.append = F,
         column.sep.width = "2pt",
         omit.stat = c("ser","f"),
         title = "Predictors of feelings towards Donald Trump and Ron DeSantis (0-100), 2021/22 Lucid")
```


\newpage
## Policy Tables 2020 Lucid
```{r, results = "asis", eval = T}
tab_labels <- c( "Immigrant Resentment", "Denial of Racism", "American$>$Latinx ID", 
                     "Right Wing Authoritarianism", "Socialism Anxiety", "Modern Sexism", "Linked Fate", 
                     "Economic Situation", "Discrimination", "Ideology (Lib-Con)", "Party ID (Dem-Rep)",
                     "Political Knowledge", "Female", "Age", "Education", "Low Income", 
                     "Middle Income", "Missing Income", "Native Born", "Spanish Language", 
                     "Protestant","Religious Importance", "Cuban", "Puerto Rican", "Other Countries")

stargazer(wall_short_2020, wall_main_2020, img_short_2020, img_main_2020, style="ajps", out.header=F,
           model.numbers = TRUE,
         covariate.labels = tab_labels,
             dep.var.labels =  c("Wall Support", "Deport Unath. Immigrants"),
          out = "Appendix_E9.tex", 
          label = "table_policy_lucid2020",
          font.size = "scriptsize",
          star.char = c("\\#", "**", "***"), 
          star.cutoffs = c(.1, .05, .01),
          notes = "$^{***}$p $<$ .01; $^{**}$p $<$ .05; $^{\\#}$p $<$ .1",
          notes.append = F,
         column.sep.width = "2pt",
         omit.stat = c("ser","f"),
         title = "Predictors of Border Wall Support and Restrictive Immigration Policy, 2020/21 Lucid")
```


\newpage
## Policy Tables 2022 Lucid
```{r, results = "asis", eval = T}
tab_labels <- c( "Immigrant Resentment", "Denial of Racism", "American$>$Latinx ID", 
                     "Right Wing Authoritarianism", "Socialism Anxiety", "Modern Sexism", "Linked Fate", 
                     "Economic Situation", "Discrimination", "Ideology (Lib-Con)", "Party ID (Dem-Rep)",
                      "Female", "Age", "Education", "Low Income", 
                     "Middle Income", "Missing Income", "Native Born", "Spanish Language", 
                     "Protestant","Religious Importance", "Cuban", "Puerto Rican", "Other Countries")

stargazer(wall_short_2022, wall_main_2022, img_short_2022, img_main_2022, style="ajps", out.header=F,
          model.numbers = TRUE,
          covariate.labels = tab_labels,
          dep.var.labels =  c("Wall Support", "Deport Unath. Immigrants"),
          out = "Appendix_E10.tex", 
          label = "table_policy_lucid2022",
          font.size = "scriptsize",
          star.char = c("\\#", "**", "***"), 
          star.cutoffs = c(.1, .05, .01),
          notes = "$^{***}$p $<$ .01; $^{**}$p $<$ .05; $^{\\#}$p $<$ .1",
          notes.append = F,
          column.sep.width = "2pt",
          omit.stat = c("ser","f"),
          title = "Predictors of Border Wall Support and Restrictive Immigration Policy, 2021/22 Lucid")
```



\newpage
## Undoc FT Table 2020 Lucid
```{r, results = "asis", eval = T}
tab_labels <- c( "Immigrant Resentment", "Denial of Racism", "American$>$Latinx ID", 
                     "Right Wing Authoritarianism", "Socialism Anxiety", "Modern Sexism", "Linked Fate", 
                     "Economic Situation", "Discrimination", "Ideology (Lib-Con)", "Party ID (Dem-Rep)",
                     "Political Knowledge", "Female", "Age", "Education", "Low Income", 
                     "Middle Income", "Missing Income", "Native Born", "Spanish Language", 
                     "Protestant","Religious Importance", "Cuban", "Puerto Rican", "Other Countries")

stargazer(img_FT_short_2020, img_FT_main_2020, style="ajps", out.header=F,
           model.numbers = TRUE,
         covariate.labels = tab_labels,
             dep.var.labels =  c("Undocumented Immigrant FT"),
          out = "Appendix_E11.tex", 
          label = "table_udocFT_lucid2022",
          font.size = "scriptsize",
          star.char = c("\\#", "**", "***"), 
          star.cutoffs = c(.1, .05, .01),
          notes = "$^{***}$p $<$ .01; $^{**}$p $<$ .05; $^{\\#}$p $<$ .1",
          notes.append = F,
         column.sep.width = "2pt",
         omit.stat = c("ser","f"),
         title = "Predictors of Feelings Toward Undocumented Immigrants, 2020/21 Lucid")
```

\newpage
## Undoc FT Table 2022 Lucid
```{r, results = "asis", eval = T}
tab_labels <- c( "Immigrant Resentment", "Denial of Racism", "American$>$Latinx ID", 
                     "Right Wing Authoritarianism", "Socialism Anxiety", "Modern Sexism", "Linked Fate", 
                     "Economic Situation", "Discrimination", "Ideology (Lib-Con)", "Party ID (Dem-Rep)",
                      "Female", "Age", "Education", "Low Income", 
                     "Middle Income", "Missing Income", "Native Born", "Spanish Language", 
                     "Protestant","Religious Importance", "Cuban", "Puerto Rican", "Other Countries")

stargazer(img_FT_short_2022, img_FT_main_2022, style="ajps", out.header=F,
          model.numbers = TRUE,
          covariate.labels = tab_labels,
          dep.var.labels =  c("Undocumented Immigrant FT"),
          out = "Appendix_E12.tex", 
          label = "table_udocFT_lucid2022",
          font.size = "scriptsize",
          star.char = c("\\#", "**", "***"), 
          star.cutoffs = c(.1, .05, .01),
          notes = "$^{***}$p $<$ .01; $^{**}$p $<$ .05; $^{\\#}$p $<$ .1",
          notes.append = F,
          column.sep.width = "2pt",
          omit.stat = c("ser","f"),
          title = "Predictors of Feelings Toward Undocumented Immigrants, 2021/22 Lucid")
```



\newpage
## Undoc Distinction Table 2020 Lucid
```{r, results = "asis", eval = T}
tab_labels <- c( "Immigrant Resentment", "Denial of Racism", "American$>$Latinx ID", 
                     "Right Wing Authoritarianism", "Socialism Anxiety", "Modern Sexism", "Linked Fate", 
                     "Economic Situation", "Discrimination", "Ideology (Lib-Con)", "Party ID (Dem-Rep)",
                     "Political Knowledge", "Female", "Age", "Education", "Low Income", 
                     "Middle Income", "Missing Income", "Native Born", "Spanish Language", 
                     "Protestant","Religious Importance", "Cuban", "Puerto Rican", "Other Countries")


stargazer(img_disct_short_2020, img_disct_main_2020, style="ajps", out.header=F,
           model.numbers = TRUE,
         covariate.labels = tab_labels,
             dep.var.labels =  c("Undocumented Distinction"),
          out = "Appendix_E13.tex", 
          label = "table_undoc_disct_lucid2020",
          font.size = "scriptsize",
          star.char = c("\\#", "**", "***"), 
          star.cutoffs = c(.1, .05, .01),
          notes = "$^{***}$p $<$ .01; $^{**}$p $<$ .05; $^{\\#}$p $<$ .1",
          notes.append = F,
         column.sep.width = "2pt",
         omit.stat = c("ser","f"),
         title = "Predictors of Distinction between Immigrant and Non-Immigrant Latinx, 2020/21 Lucid")
```


\newpage
## Undoc Distinction Table 2022 Lucid
```{r, results = "asis", eval = T}
tab_labels <- c( "Immigrant Resentment", "Denial of Racism", "American$>$Latinx ID", 
                     "Right Wing Authoritarianism", "Socialism Anxiety", "Modern Sexism", "Linked Fate", 
                     "Economic Situation", "Discrimination", "Ideology (Lib-Con)", "Party ID (Dem-Rep)",
                      "Female", "Age", "Education", "Low Income", 
                     "Middle Income", "Missing Income", "Native Born", "Spanish Language", 
                     "Protestant","Religious Importance", "Cuban", "Puerto Rican", "Other Countries")

stargazer(img_disct_short_2022, img_disct_main_2022, style="ajps", out.header=F,
          model.numbers = TRUE,
          covariate.labels = tab_labels,
          dep.var.labels =  c("Undocumented Distinction"),
          out = "Appendix_E14.tex", 
          label = "table_undoc_disct_lucid2022",
          font.size = "scriptsize",
          star.char = c("\\#", "**", "***"), 
          star.cutoffs = c(.1, .05, .01),
          notes = "$^{***}$p $<$ .01; $^{**}$p $<$ .05; $^{\\#}$p $<$ .1",
          notes.append = F,
          column.sep.width = "2pt",
          omit.stat = c("ser","f"),
          title = "Predictors of Distinction between Immigrant and Non-Immigrant Latinx, 2021/22 Lucid")
```


\newpage
## Predict Resentfulness Table 2020 Lucid
```{r, results = "asis", eval = T}
tab_labels <- c("Discrimination", "Ideology (Lib-Con)", "Party ID (Dem-Rep)",
                     "Political Knowledge", "Female", "Age", "Education", "Low Income", 
                     "Middle Income", "Missing Income", "Native Born", "Spanish Language", 
                     "Protestant","Religious Importance", "Cuban", "Puerto Rican", "Other Countries")

stargazer(resent_predict_2020, style="ajps", out.header=F,
           model.numbers = TRUE,
         covariate.labels = tab_labels,
             dep.var.labels =  c("Immigrant Resentment"),
          out = "Appendix_E1.tex", 
          label = "table_immigrant_resent_lucid2020",
          font.size = "scriptsize",
          star.char = c("\\#", "**", "***"), 
          star.cutoffs = c(.1, .05, .01),
          notes = "$^{***}$p $<$ .01; $^{**}$p $<$ .05; $^{\\#}$p $<$ .1",
          notes.append = F,
         column.sep.width = "2pt",
         omit.stat = c("ser","f"),
         title = "Predictors of Immigrant Resentment, 2020/21 Lucid")


```


\newpage
## Predict Resentfulness Table 2022 Lucid
```{r, results = "asis", eval = T}
tab_labels <- c("Discrimination", "Ideology (Lib-Con)", "Party ID (Dem-Rep)",
                     "Female", "Age", "Education", "Low Income", 
                     "Middle Income", "Missing Income", "Native Born", "Spanish Language", 
                     "Protestant","Religious Importance", "Cuban", "Puerto Rican", "Other Countries")

stargazer(resent_predict_2022, style="ajps", out.header=F,
          model.numbers = TRUE,
          covariate.labels = tab_labels,
          dep.var.labels =  c("Immigrant Resentment"),
          out = "Appendix_E2.tex", 
          label = "table_immigrant_resent_lucid2022",
          font.size = "scriptsize",
          star.char = c("\\#", "**", "***"), 
          star.cutoffs = c(.1, .05, .01),
          notes = "$^{***}$p $<$ .01; $^{**}$p $<$ .05; $^{\\#}$p $<$ .1",
          notes.append = F,
          column.sep.width = "2pt",
          omit.stat = c("ser","f"),
          title = "Predictors of Immigrant Resentment, 2021/22 Lucid")


```




\newpage
## Immigrants Different Groups Table 2022 Lucid
```{r, results = "asis", eval = T}
tab_labels <- c( "Immigrant Resentment", "Denial of Racism", "American$>$Latinx ID", 
                 "Right Wing Authoritarianism", "Socialism Anxiety", "Modern Sexism", "Linked Fate", 
                 "Economic Situation", "Discrimination", "Ideology (Lib-Con)", "Party ID (Dem-Rep)",
                 "Female", "Age", "Education", "Low Income", 
                 "Middle Income", "Missing Income", "Native Born", "Spanish Language", 
                 "Protestant","Religious Importance", "Cuban", "Puerto Rican", "Other Countries")

stargazer(img_diffgroup_short_2022, img_diffgroup_main_2022, style="ajps", out.header=F,
          model.numbers = TRUE,
          covariate.labels = tab_labels,
          dep.var.labels =  c("Immigrants Diff. Groups"),
          out = "Appendix_E15.tex", 
          label = "table_diffgroup_lucid2022",
          font.size = "scriptsize",
          star.char = c("\\#", "**", "***"), 
          star.cutoffs = c(.1, .05, .01),
          notes = "$^{***}$p $<$ .01; $^{**}$p $<$ .05; $^{\\#}$p $<$ .1",
          notes.append = F,
          column.sep.width = "2pt",
          omit.stat = c("ser","f"),
          title = "Belief that Immigrants Are Different From Latinx, 2021/22 Lucid")
```




\newpage
## Trump and Romney Therm Graph 2020 Lucid
```{r Therm Graphs, echo=FALSE, message=FALSE, warning=FALSE, fig.height=8, fig.show='asis', fig.width=12}

# prepare marginal effects as dataframe for plotting
marginal_fx_therm_2020<- rbind(margin_trump_2020, margin_romney_2020)


# IVs included in plot (creating labels)
var<-rep(c("Denial of Racism","Economic Situation", "Ideology (Lib-Con)", "Linked Fate", "Modern Sexism", "Party ID (Dem-Rep)", "Discrimination", "Immigrant Resentment", "Authoritarianism", "Socialism Anxiety", "American-Latinx ID"), times=2) 


# DVs included in plot
dep_var<-rep(c("1","2"),each=11)

#final data
marginal_fx_therm_2020<-cbind(marginal_fx_therm_2020, var, dep_var)

#labels
lab <- c(
  "1" = "Trump Feeling Therm",
  "2" = "Romney Feeling Therm")

#plot #Set the order of variables to be displayed in graph with fct_relevel function
ggplot(data = marginal_fx_therm_2020, aes(x = var%>%fct_relevel(c("Immigrant Resentment","Denial of Racism", "American-Latinx ID", "Authoritarianism", "Socialism Anxiety", "Modern Sexism","Linked Fate","Economic Situation", "Discrimination", "Ideology (Lib-Con)", "Party ID (Dem-Rep)"))%>%fct_rev, y = AME,ymin=lower, ymax = upper))+
  facet_grid(.~dep_var, labeller = as_labeller(lab))+
  geom_pointrange(size=.75,position=position_dodge(width=.5))+
  theme_bw(base_size=18,base_family="Times")+
  coord_flip()+
  scale_y_continuous(limits=c(-20,50), breaks=seq(-20, 50, 10))+
  theme(panel.grid.major.x = element_blank(),panel.grid.major.y = element_blank())+
  theme(strip.background = element_rect(fill="white"))+
  theme(strip.text.x = element_text(size = 19))+
  theme(legend.title=element_blank(),
        legend.key.size=unit(2.0, 'lines'))+
	geom_hline(yintercept=0, color="maroon", size=.5, linetype = 2) +
  theme(plot.margin=unit(c(1,2,1,1),"cm"))+
  labs(y="Change in Predicted Value of FT (Min-Max)",x=NULL,title=NULL)
  ggsave("Figure7.png", 
         width = 12, height = 8)
```


\newpage
## Trump and DeSantis Therm Graph 2022 Lucid
```{r Therm Graphs, echo=FALSE, message=FALSE, warning=FALSE, fig.height=8, fig.show='asis', fig.width=12}

# prepare marginal effects as dataframe for plotting
marginal_fx_therm_2022<- rbind(margin_trump_2022, margin_desantis_2022)


# IVs included in plot (creating labels)
var<-rep(c("Denial of Racism","Economic Situation", "Ideology (Lib-Con)", "Linked Fate", "Modern Sexism", "Party ID (Dem-Rep)", "Discrimination", "Immigrant Resentment", "Authoritarianism", "Socialism Anxiety", "American-Latinx ID"), times=2) 


# DVs included in plot
dep_var<-rep(c("1", 
               "2"),each=11)

#final data
marginal_fx_therm_2022<-cbind(marginal_fx_therm_2022, var, dep_var)

#labels
lab <- c(
  "1" = "Trump Feeling Therm", 
  "2" = "DeSantis Feeling Therm")

#plot #Set the order of variables to be displayed in graph with fct_relevel function
ggplot(data = marginal_fx_therm_2022, aes(x = var%>%fct_relevel(c("Immigrant Resentment","Denial of Racism", "American-Latinx ID", "Authoritarianism", "Socialism Anxiety", "Modern Sexism","Linked Fate","Economic Situation", "Discrimination", "Ideology (Lib-Con)", "Party ID (Dem-Rep)"))%>%fct_rev, y = AME,ymin=lower, ymax = upper))+
  facet_grid(.~dep_var, labeller = as_labeller(lab))+
  geom_pointrange(size=.75,position=position_dodge(width=.5))+
  theme_bw(base_size=18,base_family="Times")+
  coord_flip()+
  scale_y_continuous(limits=c(-20,50), breaks=seq(-20, 50, 10))+
  theme(panel.grid.major.x = element_blank(),panel.grid.major.y = element_blank())+
  theme(strip.background = element_rect(fill="white"))+
  theme(strip.text.x = element_text(size = 19))+
  theme(legend.title=element_blank(),
        legend.key.size=unit(2.0, 'lines'))+
  geom_hline(yintercept=0, color="maroon", size=.5, linetype = 2) +
  theme(plot.margin=unit(c(1,2,1,1),"cm"))+
  labs(y="Change in Predicted Value of FT (Min-Max)",x=NULL,title=NULL)
ggsave("Figure8.png", 
       width = 12, height = 8)
```




\newpage
## Policy Graph 2020 Lucid
```{r Policy Graphs, echo=FALSE, message=FALSE, warning=FALSE, fig.height=8, fig.show='asis', fig.width=12}

# prepare marginal effects as dataframe for plotting
marginal_fx_policy2020<- rbind(margin_wall_2020, margin_img_2020)


# IVs included in plot (creating labels)
var<-rep(c("Denial of Racism","Economic Situation", "Ideology (Lib-Con)", "Linked Fate", "Modern Sexism", "Party ID (Dem-Rep)", "Discrimination", "Immigrant Resentment", "Authoritarianism", "Socialism Anxiety", "American-Latinx ID"), times=2) 



# DVs included in plot
dep_var<-rep(c("1","2"),each=11)

#final data
marginal_fx_policy2020<-cbind(marginal_fx_policy2020, var, dep_var)


lab <- c(
  "1" = "Wall Support (0-4)",
  "2" = "Deport Unath. Immigrants (0-3)")

#plot #Set the order of variables to be displayed in graph with fct_relevel function
ggplot(data = marginal_fx_policy2020, aes(x = var%>%fct_relevel(c("Immigrant Resentment","Denial of Racism", "American-Latinx ID", "Authoritarianism", "Socialism Anxiety", "Modern Sexism","Linked Fate","Economic Situation", "Discrimination", "Ideology (Lib-Con)", "Party ID (Dem-Rep)"))%>%fct_rev, y = AME,ymin=lower, ymax = upper))+
  facet_grid(.~dep_var, labeller = as_labeller(lab))+
  geom_pointrange(size=.75,position=position_dodge(width=.5))+
  theme_bw(base_size=18,base_family="Times")+
  coord_flip()+
  scale_y_continuous(limits=c(-1,3), breaks=seq(-1, 3, .5))+
  theme(panel.grid.major.x = element_blank(),panel.grid.major.y = element_blank())+
  theme(strip.background = element_rect(fill="white"))+
  theme(strip.text.x = element_text(size = 19))+
  theme(legend.title=element_blank(),
        legend.key.size=unit(2.0, 'lines'))+
	geom_hline(yintercept=0, color="maroon", size=.5, linetype = 2) +
  theme(plot.margin=unit(c(1,2,1,1),"cm"))+
  labs(y="Change in Predicted Value of Policy Support/Opposition (Min-Max)",x=NULL,title=NULL)
  ggsave("Figure9.png", 
         width = 12, height = 8)
```


\newpage
## Policy Graph 2022 Lucid
```{r Policy Graphs, echo=FALSE, message=FALSE, warning=FALSE, fig.height=8, fig.show='asis', fig.width=12}

# prepare marginal effects as dataframe for plotting
marginal_fx_policy2022<- rbind(margin_wall_2022, margin_img_2022)


# IVs included in plot (creating labels)
var<-rep(c("Denial of Racism","Economic Situation", "Ideology (Lib-Con)", "Linked Fate", "Modern Sexism", "Party ID (Dem-Rep)", "Discrimination", "Immigrant Resentment", "Authoritarianism", "Socialism Anxiety", "American-Latinx ID"), times=2) 



# DVs included in plot
dep_var<-rep(c("1","2"),each=11)

#final data
marginal_fx_policy2022<-cbind(marginal_fx_policy2022, var, dep_var)


lab <- c(
  "1" = "Wall Support (0-4)",
  "2" = "Deport Unath. Immigrants (0-3)")

#plot #Set the order of variables to be displayed in graph with fct_relevel function
ggplot(data = marginal_fx_policy2022, aes(x = var%>%fct_relevel(c("Immigrant Resentment","Denial of Racism", "American-Latinx ID", "Authoritarianism", "Socialism Anxiety", "Modern Sexism","Linked Fate","Economic Situation", "Discrimination", "Ideology (Lib-Con)", "Party ID (Dem-Rep)"))%>%fct_rev, y = AME,ymin=lower, ymax = upper))+
  facet_grid(.~dep_var, labeller = as_labeller(lab))+
  geom_pointrange(size=.75,position=position_dodge(width=.5))+
  theme_bw(base_size=18,base_family="Times")+
  coord_flip()+
  scale_y_continuous(limits=c(-1,3), breaks=seq(-1, 3, .5))+
  theme(panel.grid.major.x = element_blank(),panel.grid.major.y = element_blank())+
  theme(strip.background = element_rect(fill="white"))+
  theme(strip.text.x = element_text(size = 19))+
  theme(legend.title=element_blank(),
        legend.key.size=unit(2.0, 'lines'))+
  geom_hline(yintercept=0, color="maroon", size=.5, linetype = 2) +
  theme(plot.margin=unit(c(1,2,1,1),"cm"))+
  labs(y="Change in Predicted Value of Policy Support/Opposition (Min-Max)",x=NULL,title=NULL)
ggsave("Figure10.png", 
       width = 12, height = 8)
```



\newpage
## Correlation Matrix 2020 Lucid
```{r 2020 Correlation HeatMap, echo=FALSE, message=FALSE, warning=FALSE, fig.height=8, fig.show='asis', fig.width=14}

#Correlation Matrix (Heat Map)

corr_data <-Lucid2020_short%>% 
    dplyr::select(RESENTNEGSCALE, DENYSCALE, USLATINXID, RWASCALE, SOCGEN, 
                    MODSEXISM, LF,  ECON, PDISCRIM, 
                    IDEOLOGY, PARTYID) %>% data.frame()



corr_data$RESENTNEGSCALE <-as.numeric(corr_data$RESENTNEGSCALE)
corr_data$DENYSCALE <-as.numeric(corr_data$DENYSCALE)
corr_data$USLATINXID <-as.numeric(corr_data$USLATINXID)
corr_data$RWASCALE <-as.numeric(corr_data$RWASCALE)
corr_data$SOCGEN <-as.numeric(corr_data$SOCGEN)
corr_data$MODSEXISM <-as.numeric(corr_data$MODSEXISM)
corr_data$LF <-as.numeric(corr_data$LF)
corr_data$ECON <-as.numeric(corr_data$ECON)
corr_data$PDISCRIM <-as.numeric(corr_data$PDISCRIM)
corr_data$IDEOLOGY <-as.numeric(corr_data$IDEOLOGY)
corr_data$PARTYID <-as.numeric(corr_data$PARTYID)


cormat <- round(cor(corr_data),2)


#library(reshape2) 
melted_cormat <- melt(cormat)


# Get lower triangle of the correlation matrix
get_lower_tri<-function(cormat){
  cormat[upper.tri(cormat)] <- NA
  return(cormat)
}

# Get upper triangle of the correlation matrix
get_upper_tri <- function(cormat){
  cormat[lower.tri(cormat)]<- NA
  return(cormat)
}

upper_tri <- get_upper_tri(cormat)


melted_cormat <- melt(upper_tri, na.rm = TRUE)


#Helper function to reorder the correlation matrix 
reorder_cormat <- function(cormat){
  # Use correlation between variables as distance
  dd <- as.dist((1-cormat)/2)
  hc <- hclust(dd)
  cormat <-cormat[hc$order, hc$order]
}


# Reorder the correlation matrix
cormat <- reorder_cormat(cormat)
upper_tri <- get_upper_tri(cormat)
# Melt the correlation matrix
melted_cormat <- melt(upper_tri, na.rm = TRUE)

# Create a ggheatmap
ggheatmap <- ggplot(melted_cormat, aes(Var2, Var1, fill = value))+
  geom_tile(color = "white")+
  scale_fill_gradient2(low = "blue", high = "red", mid = "white", 
                       midpoint = 0, limit = c(-1,1), space = "Lab", 
                       name="Pearson\nCorrelation") +
  theme_minimal()+ # minimal theme
  theme(axis.text.x = element_text(angle = 45, vjust = 1, 
                                   size = 12, hjust = 1))+
  coord_fixed()

# Print the heatmap
#print(ggheatmap)

ggheatmap + 
  geom_text(aes(Var2, Var1, label = value), color = "black", size = 4) +
  theme(
    axis.title.x = element_blank(),
    axis.title.y = element_blank(),
    panel.grid.major = element_blank(),
    panel.border = element_blank(),
    panel.background = element_blank(),
    axis.ticks = element_blank(),
    legend.justification = c(1, 0),
    legend.position = c(0.6, 0.7),
    legend.direction = "horizontal")+
  guides(fill = guide_colorbar(barwidth = 7, barheight = 1,
                               title.position = "top", title.hjust = 0.5)) 
           ggsave("FigureF1.png", 
         width = 14, height = 8)


```



\newpage
## Correlation Matrix 2022 Lucid
```{r 2022 Correlation HeatMap, echo=FALSE, message=FALSE, warning=FALSE, fig.height=8, fig.show='asis', fig.width=14}

#Correlation Matrix (Heat Map)

corr_data <-Lucid2022_short%>% 
  dplyr::select(RESENTNEGSCALE, DENYSCALE, USLATINXID, RWASCALE, SOCGEN, 
                MODSEXISM, LF,  ECON, PDISCRIM, 
                IDEOLOGY, PARTYID) %>% data.frame()



corr_data$RESENTNEGSCALE <-as.numeric(corr_data$RESENTNEGSCALE)
corr_data$DENYSCALE <-as.numeric(corr_data$DENYSCALE)
corr_data$USLATINXID <-as.numeric(corr_data$USLATINXID)
corr_data$RWASCALE <-as.numeric(corr_data$RWASCALE)
corr_data$SOCGEN <-as.numeric(corr_data$SOCGEN)
corr_data$MODSEXISM <-as.numeric(corr_data$MODSEXISM)
corr_data$LF <-as.numeric(corr_data$LF)
corr_data$ECON <-as.numeric(corr_data$ECON)
corr_data$PDISCRIM <-as.numeric(corr_data$PDISCRIM)
corr_data$IDEOLOGY <-as.numeric(corr_data$IDEOLOGY)
corr_data$PARTYID <-as.numeric(corr_data$PARTYID)


cormat <- round(cor(corr_data),2)


#library(reshape2) #The package reshape is required to melt the correlation matrix :
melted_cormat <- melt(cormat)


# Get lower triangle of the correlation matrix
get_lower_tri<-function(cormat){
  cormat[upper.tri(cormat)] <- NA
  return(cormat)
}

# Get upper triangle of the correlation matrix
get_upper_tri <- function(cormat){
  cormat[lower.tri(cormat)]<- NA
  return(cormat)
}

upper_tri <- get_upper_tri(cormat)


melted_cormat <- melt(upper_tri, na.rm = TRUE)


#Helper function to reorder the correlation matrix 
reorder_cormat <- function(cormat){
  # Use correlation between variables as distance
  dd <- as.dist((1-cormat)/2)
  hc <- hclust(dd)
  cormat <-cormat[hc$order, hc$order]
}


# Reorder the correlation matrix
cormat <- reorder_cormat(cormat)
upper_tri <- get_upper_tri(cormat)
# Melt the correlation matrix
melted_cormat <- melt(upper_tri, na.rm = TRUE)

# Create a ggheatmap
ggheatmap <- ggplot(melted_cormat, aes(Var2, Var1, fill = value))+
  geom_tile(color = "white")+
  scale_fill_gradient2(low = "blue", high = "red", mid = "white", 
                       midpoint = 0, limit = c(-1,1), space = "Lab", 
                       name="Pearson\nCorrelation") +
  theme_minimal()+ # minimal theme
  theme(axis.text.x = element_text(angle = 45, vjust = 1, 
                                   size = 12, hjust = 1))+
  coord_fixed()

# Print the heatmap
#print(ggheatmap)

ggheatmap + 
  geom_text(aes(Var2, Var1, label = value), color = "black", size = 4) +
  theme(
    axis.title.x = element_blank(),
    axis.title.y = element_blank(),
    panel.grid.major = element_blank(),
    panel.border = element_blank(),
    panel.background = element_blank(),
    axis.ticks = element_blank(),
    legend.justification = c(1, 0),
    legend.position = c(0.6, 0.7),
    legend.direction = "horizontal")+
  guides(fill = guide_colorbar(barwidth = 7, barheight = 1,
                               title.position = "top", title.hjust = 0.5)) 
ggsave("FigureF2.png", 
       width = 14, height = 8)


```


#ANES Regression Models \& PR Values 
```{r ANES Trump Models and Margins, include=FALSE}

# Trump Therm #
summary(trump_short_ANES<- lm (FTTRUMP ~ imgresent,
                               data = ANES2022))



summary(trump_main_ANES <- lm (FTTRUMP ~ imgresent + DENYSCALE + USLATINXID + RWASCALE + SOCGEN + 
                                 MODSEXISM + LF + ECON+ PDISCRIM+ 
                                 IDEOLOGY + PARTYID+ PKSCALE + 
                                 FEMALE + agegroup + EDUC + LT40 + INCOME4080 + INCOMEMISSING +
                                 native_born  + PROT + RELIGIOSITY + PR+ OTHER_CO,
                               data = ANES2022))

#min-max
margin_trump_ANES<- as.data.frame(summary(margins(trump_main_ANES,variables=c("imgresent",  "DENYSCALE", "USLATINXID", "RWASCALE", "SOCGEN", "MODSEXISM", "LF", "ECON","PDISCRIM", "IDEOLOGY", "PARTYID"), change = "minmax"))) %>% select(c("AME","lower","upper", "factor"))

```

```{r ANES FTUNDOCUMENTED Models and Margins, include=FALSE}

# undocumented Therm #
summary(undocumented_short_ANES<- lm (FTUNDOCUMENTED ~ imgresent,
                               data = ANES2022))



summary(undocumented_main_ANES <- lm (FTUNDOCUMENTED ~ imgresent + DENYSCALE + USLATINXID + RWASCALE + SOCGEN + 
                                 MODSEXISM + LF + ECON+ PDISCRIM+ 
                                 IDEOLOGY + PARTYID+ PKSCALE + 
                                 FEMALE + agegroup + EDUC + LT40 + INCOME4080 + INCOMEMISSING +
                                 native_born  + PROT + RELIGIOSITY + PR+ OTHER_CO,
                               data = ANES2022))

#min-max
margin_undocumented_ANES<- as.data.frame(summary(margins(undocumented_main_ANES,variables=c("imgresent",  "DENYSCALE", "USLATINXID", "RWASCALE", "SOCGEN", "MODSEXISM", "LF", "ECON","PDISCRIM", "IDEOLOGY", "PARTYID"), change = "minmax"))) %>% select(c("AME","lower","upper", "factor"))

```

```{r ANES WALL Models and Margins, include=FALSE}

# wall Therm #
summary(wall_short_ANES<- lm (WALL ~ imgresent,
                               data = ANES2022))



summary(wall_main_ANES <- lm (WALL ~ imgresent + DENYSCALE + USLATINXID + RWASCALE + SOCGEN + 
                                 MODSEXISM + LF + ECON+ PDISCRIM+ 
                                 IDEOLOGY + PARTYID+ PKSCALE + 
                                 FEMALE + agegroup + EDUC + LT40 + INCOME4080 + INCOMEMISSING +
                                 native_born  + PROT + RELIGIOSITY + PR+ OTHER_CO,
                               data = ANES2022))

#min-max
margin_wall_ANES<- as.data.frame(summary(margins(wall_main_ANES,variables=c("imgresent",  "DENYSCALE", "USLATINXID", "RWASCALE", "SOCGEN", "MODSEXISM", "LF", "ECON","PDISCRIM", "IDEOLOGY", "PARTYID"), change = "minmax"))) %>% select(c("AME","lower","upper", "factor"))

```


```{r ANES IMG Policy Models and Margins, include=FALSE}

# Img Therm #
summary(img_short_ANES<- lm (IMG ~ imgresent,
                               data = ANES2022))



summary(img_main_ANES <- lm (IMG ~ imgresent + DENYSCALE + USLATINXID + RWASCALE + SOCGEN + 
                                 MODSEXISM + LF + ECON+ PDISCRIM+ 
                                 IDEOLOGY + PARTYID+ PKSCALE + 
                                 FEMALE + agegroup + EDUC + LT40 + INCOME4080 + INCOMEMISSING +
                                 native_born  + PROT + RELIGIOSITY + PR+ OTHER_CO,
                               data = ANES2022))

#min-max
margin_img_ANES<- as.data.frame(summary(margins(img_main_ANES,variables=c("imgresent",  "DENYSCALE", "USLATINXID", "RWASCALE", "SOCGEN", "MODSEXISM", "LF", "ECON","PDISCRIM", "IDEOLOGY", "PARTYID"), change = "minmax"))) %>% select(c("AME","lower","upper", "factor"))

```



\newpage
## Undoc FT Table ANES
```{r, results = "asis", eval = T}
tab_labels <- c( "Immigrant Resentment", "Denial of Racism", "American$>$Latinx ID", 
                 "Right Wing Authoritarianism", "Socialist FT", "Modern Sexism", "Linked Fate", 
                 "Economic Situation", "Discrimination", "Ideology (Lib-Con)", "Party ID (Dem-Rep)",
                 "Political Knowledge", "Female", "Age", "Education", "Low Income", 
                 "Middle Income", "Missing Income", "Native Born", 
                 "Protestant","Religious Importance", "Puerto Rican", "Other Countries")

stargazer(undocumented_short_ANES, undocumented_main_ANES, style="ajps", out.header=F,
          model.numbers = TRUE,
          covariate.labels = tab_labels,
          dep.var.labels =  c("Undocumented Immigrant FT"),
          out = "Appendix_A1.tex", 
          label = "table_udocFT_ANES",
          font.size = "scriptsize",
          star.char = c("\\#", "**", "***"), 
          star.cutoffs = c(.1, .05, .01),
          notes = "$^{***}$p $<$ .01; $^{**}$p $<$ .05; $^{\\#}$p $<$ .1",
          notes.append = F,
          column.sep.width = "2pt",
          omit.stat = c("ser","f"),
          title = "Predictors of Feelings Toward Undocumented Immigrants, 2020 ANES")
```

\newpage
## Trump FT Table ANES
```{r, results = "asis", eval = T}
tab_labels <- c( "Immigrant Resentment", "Denial of Racism", "American$>$Latinx ID", 
                 "Right Wing Authoritarianism", "Socialist FT", "Modern Sexism", "Linked Fate", 
                 "Economic Situation", "Discrimination", "Ideology (Lib-Con)", "Party ID (Dem-Rep)",
                 "Political Knowledge", "Female", "Age", "Education", "Low Income", 
                 "Middle Income", "Missing Income", "Native Born", 
                 "Protestant","Religious Importance", "Puerto Rican", "Other Countries")

stargazer(trump_short_ANES, trump_main_ANES, style="ajps", out.header=F,
          model.numbers = TRUE,
          covariate.labels = tab_labels,
          dep.var.labels =  c("Trump FT"),
          out = "Appendix_A2.tex", 
          label = "table_trumpFT_ANES",
          font.size = "scriptsize",
          star.char = c("\\#", "**", "***"), 
          star.cutoffs = c(.1, .05, .01),
          notes = "$^{***}$p $<$ .01; $^{**}$p $<$ .05; $^{\\#}$p $<$ .1",
          notes.append = F,
          column.sep.width = "2pt",
          omit.stat = c("ser","f"),
          title = "Predictors of feelings towards Donald Trump, 2020 ANES")
```


\newpage
## Policy Attitudes Table ANES
```{r, results = "asis", eval = T}
tab_labels <- c( "Immigrant Resentment", "Denial of Racism", "American$>$Latinx ID", 
                 "Right Wing Authoritarianism", "Socialist FT", "Modern Sexism", "Linked Fate", 
                 "Economic Situation", "Discrimination", "Ideology (Lib-Con)", "Party ID (Dem-Rep)",
                 "Political Knowledge", "Female", "Age", "Education", "Low Income", 
                 "Middle Income", "Missing Income", "Native Born", 
                 "Protestant","Religious Importance", "Puerto Rican", "Other Countries")

stargazer(wall_short_ANES, wall_main_ANES, img_short_ANES, img_main_ANES, style="ajps", out.header=F,
          model.numbers = TRUE,
          covariate.labels = tab_labels,
          dep.var.labels =  c("Wall Support", "Deport Unath. Immigrants"),
          out = "Appendix_A3.tex", 
          label = "table_policy_ANES",
          font.size = "scriptsize",
          star.char = c("\\#", "**", "***"), 
          star.cutoffs = c(.1, .05, .01),
          notes = "$^{***}$p $<$ .01; $^{**}$p $<$ .05; $^{\\#}$p $<$ .1",
          notes.append = F,
          column.sep.width = "2pt",
          omit.stat = c("ser","f"),
          title = "Predictors of Border Wall Support and Restrictive Immigration Policy, 2020 ANES")
```



\newpage
## Policy Graph 2020 ANES
```{r Policy Graphs ANES, echo=FALSE, message=FALSE, warning=FALSE, fig.height=8, fig.show='asis', fig.width=12}

# prepare marginal effects as dataframe for plotting
marginal_fx_policy_ANES<- rbind(margin_wall_ANES, margin_img_ANES)


# IVs included in plot (creating labels)
var<-rep(c("Denial of Racism", "Economic Situation", "Ideology (Lib-Con)", "Immigrant Resentment", 
           "Linked Fate", "Modern Sexism", "Party ID (Dem-Rep)", "Discrimination", 
           "Authoritarianism", "Socialist Feeling Therm.", "American-Latinx ID"), times=2) 



# DVs included in plot
dep_var<-rep(c("1","2"),each=11)

#final data
marginal_fx_policy_ANES<-cbind(marginal_fx_policy_ANES, var, dep_var)


lab <- c(
  "1" = "Wall Support (0-4)",
  "2" = "Deport Unath. Immigrants (0-4)")

#plot #Set the order of variables to be displayed in graph with fct_relevel function
ggplot(data = marginal_fx_policy_ANES, aes(x = var%>%fct_relevel(c("Immigrant Resentment","Denial of Racism", "American-Latinx ID", "Authoritarianism", "Socialist Feeling Therm.", "Modern Sexism","Linked Fate","Economic Situation", "Discrimination", "Ideology (Lib-Con)", "Party ID (Dem-Rep)"))%>%fct_rev, y = AME,ymin=lower, ymax = upper))+
  facet_grid(.~dep_var, labeller = as_labeller(lab))+
  geom_pointrange(size=.75,position=position_dodge(width=.5))+
  theme_bw(base_size=18,base_family="Times")+
  coord_flip()+
  scale_y_continuous(limits=c(-1.5,3), breaks=seq(-1, 3, .5))+
  theme(panel.grid.major.x = element_blank(),panel.grid.major.y = element_blank())+
  theme(strip.background = element_rect(fill="white"))+
  theme(strip.text.x = element_text(size = 19))+
  theme(legend.title=element_blank(),
        legend.key.size=unit(2.0, 'lines'))+
  geom_hline(yintercept=0, color="maroon", size=.5, linetype = 2) +
  theme(plot.margin=unit(c(1,2,1,1),"cm"))+
  labs(y="Change in Predicted Value of Policy Support/Opposition (Min-Max)",x=NULL,title=NULL)
ggsave("Figure2.png", 
       width = 12, height = 8)
```


\newpage
## TRUMP Graph 2020 ANES
```{r Trump Graph ANES, echo=FALSE, message=FALSE, warning=FALSE, fig.height=8, fig.show='asis', fig.width=12}

# prepare marginal effects as dataframe for plotting
marginal_fx_trump_ANES<- margin_trump_ANES


# IVs included in plot (creating labels)
var<-rep(c("Denial of Racism", "Economic Situation", "Ideology (Lib-Con)", "Immigrant Resentment", 
           "Linked Fate", "Modern Sexism", "Party ID (Dem-Rep)", "Discrimination", 
           "Authoritarianism", "Socialist Feeling Therm.", "American-Latinx ID"), times=1) 



# DVs included in plot
dep_var<-rep(c("1"),each=11)

#final data
marginal_fx_trump_ANES<-cbind(marginal_fx_trump_ANES, var, dep_var)


lab <- c(
  "1" = "Trump Feeling Therm"
  )

#plot #Set the order of variables to be displayed in graph with fct_relevel function
ggplot(data = marginal_fx_trump_ANES, aes(x = var%>%fct_relevel(c("Immigrant Resentment","Denial of Racism", "American-Latinx ID", "Authoritarianism", "Socialist Feeling Therm.", "Modern Sexism","Linked Fate","Economic Situation", "Discrimination", "Ideology (Lib-Con)", "Party ID (Dem-Rep)"))%>%fct_rev, y = AME,ymin=lower, ymax = upper))+
  facet_grid(.~dep_var, labeller = as_labeller(lab))+
  geom_pointrange(size=.75,position=position_dodge(width=.5))+
  theme_bw(base_size=18,base_family="Times")+
  coord_flip()+
  scale_y_continuous(limits=c(-30,60), breaks=seq(-30, 60, 10))+
  theme(panel.grid.major.x = element_blank(),panel.grid.major.y = element_blank())+
  theme(strip.background = element_rect(fill="white"))+
  theme(strip.text.x = element_text(size = 19))+
  theme(legend.title=element_blank(),
        legend.key.size=unit(2.0, 'lines'))+
  geom_hline(yintercept=0, color="maroon", size=.5, linetype = 2) +
  theme(plot.margin=unit(c(1,2,1,1),"cm"))+
  labs(y="Change in Predicted Value of Trump FT (Min-Max)",x=NULL,title=NULL)
ggsave("Figure1.png", 
       width = 12, height = 8)
```



#CMPS Regression Models \& PR Values 
```{r CMPS Trump FavModels and Margins, include=FALSE}

# Trump Fav 0-4 #
summary(trump_short_CMPS<- lm (trumpfav ~ antilatino,
                               data = CMPS2016))



summary(trump_main_CMPS <- lm (trumpfav ~ antilatino + ushispid + pdiscrim + lf + usecon+ 
                                 ideology + party+ 
                                 female + agegroup + educ + incomelt40 + income4080 +
                                 native_born+ prot+ pr + cuba+ OTHER_CO,
                               data = CMPS2016))

#min-max
margin_trump_CMPS<- as.data.frame(summary(margins(trump_main_CMPS,variables=c("antilatino",  "ushispid", "pdiscrim", "lf", "usecon", "ideology", "party"), change = "minmax"))) %>% select(c("AME","lower","upper", "factor"))

```


```{r CMPS Trump Vote Models and Margins, include=FALSE}

# Trump Vote 0-1 #
summary(trump_vote_short_CMPS<- lm (trumpvote ~ antilatino,
                               data = CMPS2016))



summary(trump_vote_main_CMPS <- lm (trumpvote ~ antilatino + ushispid + pdiscrim + lf + usecon+ 
                                 ideology + party+ 
                                 female + agegroup + educ + incomelt40 + income4080 +
                                 native_born+ prot+ pr + cuba+ OTHER_CO,
                               data = CMPS2016))

#min-max
margin_trump_vote_CMPS<- as.data.frame(summary(margins(trump_vote_main_CMPS,variables=c("antilatino",  "ushispid", "pdiscrim", "lf", "usecon", "ideology", "party"), change = "minmax"))) %>% select(c("AME","lower","upper", "factor"))

```


 
```{r CMPS deport Models and Margins, include=FALSE}

# Deport 0-1 #
summary(deport_short_CMPS<- lm (deport ~ antilatino,
                               data = CMPS2016))



summary(deport_main_CMPS <- lm (deport ~ antilatino + ushispid + pdiscrim + lf + usecon+ 
                                 ideology + party+ 
                                 female + agegroup + educ + incomelt40 + income4080 +
                                 native_born+ prot+ pr + cuba+ OTHER_CO,
                               data = CMPS2016))

#min-max
margin_deport_CMPS<- as.data.frame(summary(margins(deport_main_CMPS,variables=c("antilatino",  "ushispid", "pdiscrim", "lf", "usecon", "ideology", "party"), change = "minmax"))) %>% select(c("AME","lower","upper", "factor"))

```


```{r CMPS imgcitizen Models and Margins, include=FALSE}

# imgcitizen 0-4 #
summary(imgcitizen_short_CMPS<- lm (imgcitizen ~ antilatino,
                               data = CMPS2016))



summary(imgcitizen_main_CMPS <- lm (imgcitizen ~ antilatino + ushispid + pdiscrim + lf + usecon+ 
                                 ideology + party+ 
                                 female + agegroup + educ + incomelt40 + income4080 +
                                 native_born+ prot+ pr + cuba+ OTHER_CO,
                               data = CMPS2016))

#min-max
margin_imgcitizen_CMPS<- as.data.frame(summary(margins(imgcitizen_main_CMPS,variables=c("antilatino",  "ushispid", "pdiscrim", "lf", "usecon", "ideology", "party"), change = "minmax"))) %>% select(c("AME","lower","upper", "factor"))

```



 
\newpage
## Trump Fav and Vote Table CMPS
```{r, results = "asis", eval = T}
tab_labels <- c( "Immigrant Resentment", "American$>$Latinx ID", 
                 "Discrimination", "Linked Fate", 
                 "Economic Situation", "Ideology (Lib-Con)", "Party ID (Dem-Rep)",
                 "Female", "Age", "Education", "Low Income", 
                 "Middle Income", "Native Born", 
                 "Protestant", "Puerto Rican", "Cuban", "Other Countries")

stargazer(trump_short_CMPS, trump_main_CMPS, trump_vote_short_CMPS, trump_vote_main_CMPS, style="ajps", out.header=F,
          model.numbers = TRUE,
          covariate.labels = tab_labels,
          dep.var.labels =  c("Trump Fav (0-4)", "Trump Vote (0-1)"),
          out = "Appendix_A4.tex", 
          label = "table_trump_cmps",
          font.size = "scriptsize",
          star.char = c("\\#", "**", "***"), 
          star.cutoffs = c(.1, .05, .01),
          notes = "$^{***}$p $<$ .01; $^{**}$p $<$ .05; $^{\\#}$p $<$ .1",
          notes.append = F,
          column.sep.width = "2pt",
          omit.stat = c("ser","f"),
          title = "Predictors of Donald Trump Favorability and Vote Choice, 2016 CMPS")
```



\newpage
## Immigration Policy Attitudes Table CMPS
```{r, results = "asis", eval = T}
tab_labels <- c( "Immigrant Resentment", "American$>$Latinx ID", 
                 "Discrimination", "Linked Fate", 
                 "Economic Situation", "Ideology (Lib-Con)", "Party ID (Dem-Rep)",
                 "Female", "Age", "Education", "Low Income", 
                 "Middle Income", "Native Born", 
                 "Protestant", "Puerto Rican", "Cuban", "Other Countries")

stargazer(deport_short_CMPS, deport_main_CMPS, imgcitizen_short_CMPS, imgcitizen_main_CMPS, style="ajps", out.header=F,
          model.numbers = TRUE,
          covariate.labels = tab_labels,
          dep.var.labels =  c("Deport Undocumented Immigrants (0-1)", "Pathway to Citizenship (0-4)"),
          out = "Appendix_A5.tex", 
          label = "table_policy_cmps",
          font.size = "scriptsize",
          star.char = c("\\#", "**", "***"), 
          star.cutoffs = c(.1, .05, .01),
          notes = "$^{***}$p $<$ .01; $^{**}$p $<$ .05; $^{\\#}$p $<$ .1",
          notes.append = F,
          column.sep.width = "2pt",
          omit.stat = c("ser","f"),
          title = "Predictors of Immigration Policy Attitudes, 2016 CMPS")
```



\newpage
## Policy Graph 2016 CMPS
```{r Policy Graphs CMPS, echo=FALSE, message=FALSE, warning=FALSE, fig.height=8, fig.show='asis', fig.width=12}

# prepare marginal effects as dataframe for plotting
marginal_fx_policy_CMPS<- rbind(margin_deport_CMPS, margin_imgcitizen_CMPS)


# IVs included in plot (creating labels)
var<-rep(c("Immigrant Resentment", "Ideology (Lib-Con)",  "Linked Fate", 
           "Party ID (Dem-Rep)",  "Discrimination",  "Economic Situation",
           "American-Latinx ID"), times=2) 



# DVs included in plot
dep_var<-rep(c("1","2"),each=7)

#final data
marginal_fx_policy_CMPS<-cbind(marginal_fx_policy_CMPS, var, dep_var)


lab <- c(
  "1" = "Deport Undoc. Imm. (0-1)",
  "2" = "Oppose Pathway Citizenship (0-4)")

#plot #Set the order of variables to be displayed in graph with fct_relevel function
ggplot(data = marginal_fx_policy_CMPS, aes(x = var%>%fct_relevel(c("Immigrant Resentment", "American-Latinx ID", "Linked Fate","Economic Situation", "Discrimination", "Ideology (Lib-Con)", "Party ID (Dem-Rep)"))%>%fct_rev, y = AME,ymin=lower, ymax = upper))+
  facet_grid(.~dep_var, labeller = as_labeller(lab))+
  geom_pointrange(size=.75,position=position_dodge(width=.5))+
  theme_bw(base_size=18,base_family="Times")+
  coord_flip()+
  scale_y_continuous(limits=c(-.3,.8), breaks=seq(-.2, .8, .2))+
  theme(panel.grid.major.x = element_blank(),panel.grid.major.y = element_blank())+
  theme(strip.background = element_rect(fill="white"))+
  theme(strip.text.x = element_text(size = 19))+
  theme(legend.title=element_blank(),
        legend.key.size=unit(2.0, 'lines'))+
  geom_hline(yintercept=0, color="maroon", size=.5, linetype = 2) +
  theme(plot.margin=unit(c(1,2,1,1),"cm"))+
  labs(y="Change in Predicted Value of Policy Support/Opposition (Min-Max)",x=NULL,title=NULL)
ggsave("Figure4.png", 
       width = 12, height = 8)
```


\newpage
## Trump Graph 2016 CMPS
```{r Trump Graphs CMPS, echo=FALSE, message=FALSE, warning=FALSE, fig.height=8, fig.show='asis', fig.width=12}

# prepare marginal effects as dataframe for plotting
marginal_fx_trump_CMPS<- rbind(margin_trump_CMPS, margin_trump_vote_CMPS)


# IVs included in plot (creating labels)
var<-rep(c("Immigrant Resentment", "Ideology (Lib-Con)",  "Linked Fate", 
           "Party ID (Dem-Rep)",  "Discrimination",  "Economic Situation",
           "American-Latinx ID"), times=2) 



# DVs included in plot
dep_var<-rep(c("1","2"),each=7)

#final data
marginal_fx_trump_CMPS<-cbind(marginal_fx_trump_CMPS, var, dep_var)


lab <- c(
  "1" = "Trump Favorability (0-4)",
  "2" = "Trump Vote (0-1)")

#plot #Set the order of variables to be displayed in graph with fct_relevel function
ggplot(data = marginal_fx_trump_CMPS, aes(x = var%>%fct_relevel(c("Immigrant Resentment", "American-Latinx ID", "Linked Fate","Economic Situation", "Discrimination", "Ideology (Lib-Con)", "Party ID (Dem-Rep)"))%>%fct_rev, y = AME,ymin=lower, ymax = upper))+
  facet_grid(.~dep_var, labeller = as_labeller(lab))+
  geom_pointrange(size=.75,position=position_dodge(width=.5))+
  theme_bw(base_size=18,base_family="Times")+
  coord_flip()+
  scale_y_continuous(limits=c(-.7,2), breaks=seq(-.6, 2, .4))+
  theme(panel.grid.major.x = element_blank(),panel.grid.major.y = element_blank())+
  theme(strip.background = element_rect(fill="white"))+
  theme(strip.text.x = element_text(size = 19))+
  theme(legend.title=element_blank(),
        legend.key.size=unit(2.0, 'lines'))+
  geom_hline(yintercept=0, color="maroon", size=.5, linetype = 2) +
  theme(plot.margin=unit(c(1,2,1,1),"cm"))+
  labs(y="Change in Predicted Value of Trump Fav. and Vote (Min-Max)",x=NULL,title=NULL)
ggsave("Figure3.png", 
       width = 12, height = 8)
```


